﻿using UnityEngine;

namespace Gp.Scripts.Core {
    public class MoveGestureTrigger : UnitGestureTrigger {
        private readonly Vector3 _destination;
        private static readonly int DashForward = Animator.StringToHash("DashForward");
        private static readonly int DashSide = Animator.StringToHash("DashSide");

        
        public MoveGestureTrigger(Vector3 destination) {
            _destination = destination;
        }


        public override void OnTrigger() {
            var matrix = UnitReference.transform.worldToLocalMatrix;
            var delta = matrix.MultiplyPoint(_destination) - UnitReference.transform.localPosition;
            delta.y = 0;
            var moveDir = delta.normalized;
            // 转换为本地坐标
            Animator.SetFloat(DashForward, moveDir.x);
            Animator.SetFloat(DashSide, moveDir.z);
            
            Animator.Play(UnitAnimatorStateId.DashState);
        }
    }
}